package pers.zh.parking.mvp.model;

import android.app.Application;

import com.google.gson.Gson;

import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;
import pers.zh.parking.common.ApiService;
import pers.zh.parking.common.BaseResponse;
import pers.zh.parking.data.entity.Car;
import pers.zh.parking.mvp.contract.MyCarsContract;

@ActivityScope
public class MyCarsModel extends BaseModel implements MyCarsContract.Model {

    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public MyCarsModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseResponse<List<Car>>> getCars(String userId) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).getCars(userId);
    }

    @Override
    public Observable<BaseResponse> addCar(Car car) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).addCar(car);
    }

    @Override
    public Observable<BaseResponse> updateCar(Car car) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).updateCar(car);
    }

    @Override
    public Observable<BaseResponse> delete(List<Car> cars) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).deleteCars(cars);
    }
}